﻿@page "/configure"

<h3>Manage Runs</h3>
<label for="CollectionRunsSelect">Collection Runs</label>
<select id="CollectionRunsSelect" @bind="SelectedRun">
    @for (int i = 0; i < Runs.Count; i++)
    {
        <option value="@i">@Runs[i]</option>
    }
</select>
<button @onclick="DeleteSelected">Delete Selected Run</button>
<br />
<label for="CompareRunsSelect">Comparison Runs</label>
<select id="CompareRunsSelect" @bind="SelectedCompareRun">
    @for (int i = 0; i < CompareRuns.Count; i++)
    {
        <option value="@i">@CompareRuns[i]</option>
    }
</select>
<button @onclick="DeleteSelectedCompare">Delete Selected Run</button>
<br />

@code {
    public int SelectedRun { get; set; }

    public int SelectedCompareRun { get; set; }

    public List<string> Runs = AttackSurfaceAnalyzerClient.DatabaseManager.GetRuns();

    public List<(string firstRunId, string secondRunId, string analysesHash, RUN_STATUS runStatus)> CompareRuns = AttackSurfaceAnalyzerClient.DatabaseManager.GetCompareRuns();

    public void DeleteSelected()
    {
        AttackSurfaceAnalyzerClient.DatabaseManager.DeleteRun(Runs[SelectedRun]);
        Runs = AttackSurfaceAnalyzerClient.DatabaseManager.GetRuns();
        this.StateHasChanged();
    }

    public void DeleteSelectedCompare()
    {
        AttackSurfaceAnalyzerClient.DatabaseManager.DeleteCompareRun(CompareRuns[SelectedCompareRun].firstRunId, CompareRuns[SelectedCompareRun].secondRunId, CompareRuns[SelectedCompareRun].analysesHash);
        CompareRuns = AttackSurfaceAnalyzerClient.DatabaseManager.GetCompareRuns();
        this.StateHasChanged();
    }
}
